[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
atan2() Calculate Arc Tangent of y/x
#include <math.h>
double atan2(y,x); Arc tangent (in radians)
double y; y coordinate value
double x; x coordinate value
atan2() returns the arc tangent of 'y'/'x' in radians. The value
returned is in the range -pi to pi. 'x' and 'y' cannot both be 0.0.
Returns: Arc tangent of 'y'/'x'. If both 'x' and 'y' are 0.0,
then matherr() is called with a DOMAIN error; a
domain error message is printed to 'stderr'; 'errno'
(defined in <errno.h>) is set to EDOM (defined in
math.h); and 0.0 is returned.
Notes: You can modify error handling with the matherr()
routine.
-------------------------------- Example ---------------------------------
The following statements print the arc tangent of 20.0/0.0 and try to
calculate the arc tangent of 0.0/0.0, which causes an EDOM error.
#include <math.h> /* for atan2() and EDOM */
#include <stdio.h> /* for printf() */
#include <errno.h> /* for errno */
main()
{
double arc_tan;
arc_tan = atan2(20.0, 0.0); /* arc_tan = pi/2 (1.570796) */
printf("arc tangent of 20/0 is %.6f radians\n", arc_tan);
errno = 0;
arc_tan = atan2(0.0, 0.0); /* arc_tan = 0, causes an error */
/* a DOMAIN error message is also printed to stderr */
if (errno == EDOM)
printf("DOMAIN error in atan2()\n");
}
See Also:
atan()
matherr()
_matherr()
sin()
tan()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson